/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.zx.customer.points.details.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.zx.customer.points.details.entity.TcustomerPointsDetails;
import com.jeesite.modules.zx.customer.points.details.service.TcustomerPointsDetailsService;

/**
 * 客户积分明细Controller
 * @author zpp
 * @version 2020-03-13
 */
@Controller
@RequestMapping(value = "${adminPath}/zx/customer/points/details/tcustomerPointsDetails")
public class TcustomerPointsDetailsController extends BaseController {

	@Autowired
	private TcustomerPointsDetailsService tcustomerPointsDetailsService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public TcustomerPointsDetails get(String id, boolean isNewRecord) {
		return tcustomerPointsDetailsService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("zx:customer:points:details:view")
	@RequestMapping(value = {"list", ""})
	public String list(TcustomerPointsDetails tcustomerPointsDetails, Model model) {
		model.addAttribute("tcustomerPointsDetails", tcustomerPointsDetails);
		return "modules/zx/customer/points/details/tcustomerPointsDetailsList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("zx:customer:points:details:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<TcustomerPointsDetails> listData(TcustomerPointsDetails tcustomerPointsDetails, HttpServletRequest request, HttpServletResponse response) {
		tcustomerPointsDetails.setPage(new Page<>(request, response));
		Page<TcustomerPointsDetails> page = tcustomerPointsDetailsService.findPage(tcustomerPointsDetails);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("zx:customer:points:details:view")
	@RequestMapping(value = "form")
	public String form(TcustomerPointsDetails tcustomerPointsDetails, Model model) {
		model.addAttribute("tcustomerPointsDetails", tcustomerPointsDetails);
		return "modules/zx/customer/points/details/tcustomerPointsDetailsForm";
	}

	/**
	 * 保存客户积分明细
	 */
	@RequiresPermissions("zx:customer:points:details:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated TcustomerPointsDetails tcustomerPointsDetails) {
		tcustomerPointsDetailsService.save(tcustomerPointsDetails);
		return renderResult(Global.TRUE, text("保存客户积分明细成功！"));
	}
	
	/**
	 * 停用客户积分明细
	 */
	@RequiresPermissions("zx:customer:points:details:edit")
	@RequestMapping(value = "disable")
	@ResponseBody
	public String disable(TcustomerPointsDetails tcustomerPointsDetails) {
		tcustomerPointsDetails.setStatus(TcustomerPointsDetails.STATUS_DISABLE);
		tcustomerPointsDetailsService.updateStatus(tcustomerPointsDetails);
		return renderResult(Global.TRUE, text("停用客户积分明细成功"));
	}
	
	/**
	 * 启用客户积分明细
	 */
	@RequiresPermissions("zx:customer:points:details:edit")
	@RequestMapping(value = "enable")
	@ResponseBody
	public String enable(TcustomerPointsDetails tcustomerPointsDetails) {
		tcustomerPointsDetails.setStatus(TcustomerPointsDetails.STATUS_NORMAL);
		tcustomerPointsDetailsService.updateStatus(tcustomerPointsDetails);
		return renderResult(Global.TRUE, text("启用客户积分明细成功"));
	}
	
	/**
	 * 删除客户积分明细
	 */
	@RequiresPermissions("zx:customer:points:details:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(TcustomerPointsDetails tcustomerPointsDetails) {
		tcustomerPointsDetailsService.delete(tcustomerPointsDetails);
		return renderResult(Global.TRUE, text("删除客户积分明细成功！"));
	}
	
}